﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {


            // Text1();  
            // Text2();
               Text3();
        }

        private static void Text3()
        {

            Book book = new Book();
            book._num = "s2001";
            book._Name = "收购阿里巴巴";
            book.Price = -2;
            book._ChuBanShe = "重庆出版社";
            book._ZuoZhe = "万岁爷";
            book.Print();
        }

        private static void Text2()
        {
            //2.定义一个学生类，存放学生的学号、姓名、性别、年龄、专业信息；
            //对年龄字段进行赋值的安全性设置，如果是非法值（小于0或者大于128岁），该年龄值为0；
            //在学生类中定义一个方法输出学生信息。
            //在主方法实例化对象，赋值并输出

            Student stu = new Student();
            stu.num = 20021;
            stu.name = "张三";
            stu.Age = 19;
            stu.zhuanye = "软件工程";
            stu.Print();


        }

        private static void Text1()
        {
            YongHu yongHu = new YongHu();
            yongHu.name = "张三";
            yongHu.zhangHao = "admin";
            yongHu.passWord = "123";
            yongHu.Print();
        }
    }
    class Book
    {
        //3.定义一个图书类，存放图书的编号、书名、价格、出版社、作者信息；
        //对价格进行赋值限制，小于0价格，赋值为0
        //在图书类中定义一个方法输出图书信息；
        //在主方法实例化对象，赋值并输出
        public string _num { get; set; }
        public string _Name { get; set; }
        private int _Price;
        public int Price
        {
            get { return _Price; }
            set {
                if (value <= 0)
                {
                    value = 0;
                }
                _Price = value;
                Console.WriteLine("价格不合法！默认为0");
            }
        }
        public string _ChuBanShe { get; set; }
        public string _ZuoZhe { get; set; }

        public Book(string num, string name, int price, string chubanshe, string zuozhe)
        {
            _num = num;
            _Name = name;
            _Price = price;
            _ChuBanShe = chubanshe;
            _ZuoZhe = zuozhe;
        }
        public Book(){}
        public void Print() 
        {
            Console.WriteLine($"编号{_num},书名是{_Name},价格是{Price},出版社是{_ChuBanShe},作者是{_ZuoZhe}");
        }




    }
    class Student
    {
        public int num;
        public string name;
        public string zhuanye;

        private int age;

        public int Age
        {
            get { return age; }
            set {
                if (value <= 0 || value >= 128)  //判断 写入的值是否满足if条件 如果是，赋值0
                {
                    Console.WriteLine("年龄非法！默认为0");
                    value = 0;
                }
                age = value;
            }

        }

        public Student(int Num,string Name,string Zhuanye,int Age)
        {
            num = Num;
            name = Name;
            zhuanye = Zhuanye;
            age = Age;
        }
        public Student(){}
        public void Print()
        {
            Console.WriteLine("我的学号是{0},我的姓名是{1},我的年龄是:{2},我的专业是{3}",num,name,Age,zhuanye);
        }

    }
    class YongHu
    {
        //1. 定义一个用户类，存放用户的账号、用户名和密码属性；
        //   在用户类中定义一个方法输出当前用户对象的账号、用户名和密码的信息；
        //   然后在主方法调用输出；

      
        public string zhangHao { get; set; }
        public string name { get; set; }
        public string passWord { get; set; }


        public void Print()
        {
            Console.WriteLine("我的账号是{0},我的姓名是{1},我的密码是{2}", zhangHao, name, passWord);
        }


    }

}
